﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace BloodThirsty
{
    public class Button : Dialog
    {
        private Texture2D[] _Textture;
        static int i = 0;

        
        public Texture2D[] Textture
        {
            get { return _Textture; }
            set { _Textture = value;
            _nTexture = _Textture.Length;
            _iTexture = 0;
            
            }
        }
        private int _state = 0;

        public int State
        {
            get { return _state; }
            set { _state = value; }
        }
        private int _nTexture;

        public int nTexture
        {
            get { return _nTexture; }
            set { _nTexture = value; }
        }

        private int _iTexture;

        public int iTexture
        {
            get { return _iTexture; }
            set { _iTexture = value; }
        }
        private double _Left;

        public double Left
        {
            get { return _Left; }
            set { _Left = value; }
        }
        private double _Top;

        public double Top
        {
            get { return _Top; }
            set { _Top = value; }
        }

        private double _Width;

        public double Width1
        {
            get { return _Width; }
            set { _Width = value; }
        }
        private double _Height;

        public double Height1
        {
            get { return _Height; }
            set { _Height = value; }
        }
        public Button(Texture2D[] texture, double left, double top)
        {
            Textture = texture;
            Left = left;
            Top = top;
        }

        private bool _ketThucMenu = false;

        public bool KetThucMenu
        {
            get { return _ketThucMenu; }
            set { _ketThucMenu = value; }
        }

        //Tra ve button dc chuot tro vao
        public int IsSelected(double x, double y)
        {
            
            int i = 0;
            if (KetThucMenu == false)
            {
                if (x > 920 && x <= 920 + 250 && y > 250 && y <= 250 + 56)
                {
                    i = 1;
                    
                }
                if (x > 920 && x <= 920 + 250 && y > 315 && y <= 315 + 56)
                {
                    i = 2;
                    
                }
                if (x > 920 && x <= 920 + 250 && y > 380 && y <= 380 + 56)
                {
                    i = 3;
                }
                if (x > 920 && x <= 920 + 250 && y > 445 && y <= 445 + 56)
                {
                    i = 4;
                }
                if (x > 920 && x <= 920 + 250 && y > 510 && y <= 510 + 56)
                {
                    i = 5;
                }
                if (x > 920 && x <= 920 + 250 && y > 575 && y <= 575 + 56)
                {
                    i = 6;
                }
                // Vi ko biet cach lay vi tri cua 1 texture nen phai gan truc tiep vi tri len bang so 
            }
            else
            {
                i = 0;
            }
            return i;
        }
        

        
        public void Update(GameTime gametime)
        {
            if (Left <= 900)
            {
                Left = Left + i;
                i++;
            }
            else
            {
                Left = Left;
            }

            
            iTexture = (iTexture + 1) % (nTexture/2);

        }

        public void Draw(GameTime gametime, SpriteBatch spriteBatch)
        {

            // Ham ve nay kiem them nhiem vu lap vi tri Top ban dau cho cac button
            Top = 235;
            for (iTexture = 0; iTexture < nTexture / 2; iTexture++)
            {
                spriteBatch.Draw(Textture[iTexture], new Vector2((float)Left, (float)Top), Color.White);
                if (State == 1 && iTexture == 0)
                {
                    spriteBatch.Draw(Textture[0+6], new Vector2((float)Left, (float)Top), Color.White);
                }
                if (State == 2 && iTexture == 1)
                {
                    spriteBatch.Draw(Textture[1 + 6], new Vector2((float)Left, (float)Top), Color.White);
                }
                if (State == 3 && iTexture == 2)
                {
                    spriteBatch.Draw(Textture[2 + 6], new Vector2((float)Left, (float)Top), Color.White);
                }
                if (State == 4 && iTexture == 3)
                {
                    spriteBatch.Draw(Textture[3 + 6], new Vector2((float)Left, (float)Top), Color.White);
                }
                if (State == 5 && iTexture == 4)
                {
                    spriteBatch.Draw(Textture[4 + 6], new Vector2((float)Left, (float)Top), Color.White);
                }
                if (State == 6 && iTexture == 5)
                {
                    spriteBatch.Draw(Textture[5 + 6], new Vector2((float)Left, (float)Top), Color.White);
                }
               
                
                Top = Top + 65;
            }
           
        }
    }
}
